const service = require('../../utils/service.js')
const api = require('../../utils/util.js')
Page({
  data: {
    myIncome: {},
    list: {},
    yzc: {},
    is_Yzc: false,
    tabIndex: 0,
    bind: '未绑定'
  },
  init: function() {
    let self = this;
    this.getList(0, function(res) {
      if (res.code == 0) {
        let bind = res.data.bindBank == 1 ? "已绑定" : "未绑定";
        self.data.list = res.data;
        if (!self.data.is_Yzc) {
          self.setData({
            myIncome: self.data.list,
            bind: bind
          });
        }
      } else {
        api.toast(res.message || '数据出现错误！')
      }
    });
    this.getList(1, function(res) {
      if (res.code == 0) {
        let bind = res.data.bindBank == 1 ? "已绑定" : "未绑定";
        self.data.yzc = res.data;
        if (self.data.is_Yzc) {
          self.setData({
            myIncome: self.data.yzc,
            bind: bind
          });
        }
      } else {
        api.toast(res.message || '数据出现错误！')
      }
    });
  },
  getList: function(isYzc, callback) {
    let self = this,
      shop_code = wx.getStorageSync('shopInfo').shop_code,
      shopData = wx.getStorageSync('shop_data');
    api.ajax(service.url('getTradingMoney'), {
      unionid: shopData.shop_unionid,
      token: shopData.token,
      token_key: shopData.token_key,
      shop_code: shop_code,
      yzc_status: isYzc
    }, function(res) {
      console.log('shopIncomeMoney：' + JSON.stringify(res));
      callback(res);
    });
  },
  shopIncomeTab: function(et) {
    let index = +et.currentTarget.dataset.index;
    let yzc = index == 0 ? false : true;
    let list = index == 0 ? this.data.list : this.data.yzc;
    this.setData({
      myIncome: list,
      tabIndex: index,
      is_Yzc: yzc
    });
  },
  //--交易中  
  openTradingList: function() {
    wx.navigateTo({
      url: '../shop_income/trading/trading?title=' + (this.data.is_Yzc ? '交易中-YZC收入' : '交易中-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  //--可提现  
  openWithdrawMoney: function() {
    wx.navigateTo({
      url: '../shop_income/withdraw/withdraw?title=' + (this.data.is_Yzc ? '可提现-YZC收入' : '可提现-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  //--结算中  
  openClearingList: function() {
    wx.navigateTo({
      url: '../shop_income/clearing/clearing?title=' + (this.data.is_Yzc ? '结算中-YZC收入' : '结算中-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  //--已提现  
  openAlreadyList: function() {
    wx.navigateTo({
      url: '../shop_income/already/already?title=' + (this.data.is_Yzc ? '已提现-YZC收入' : '已提现-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  //--绑定银行卡
  openBindBank: function() {
    wx.navigateTo({
      url: '../shop_income/bank/bank?title=' + (this.data.is_Yzc ? '已提现-YZC收入' : '已提现-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  //--收支明细
  openDetailList: function() {
    wx.navigateTo({
      url: '../shop_income/detail/detail?title=' + (this.data.is_Yzc ? '收支明细-YZC收入' : '收支明细-现金收入') + '&yzc_status=' + (this.data.is_Yzc ? 1 : 0)
    });
  },
  /**
   * 页面上拉触底事件的处理函数  
   */
  onReachBottom: function() {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  /**
   * 页面显示/切入前台时触发
   */
  onShow: function() {
    this.init();
  }
})